package cn.xz.zgsg

import cn.xz.zgsg.activity.*
import cn.xz.zgsg.base.BaseActivity
import cn.xz.zgsg.bean.CommonLib
import cn.xz.zgsg.bean.DateLogin
import cn.xz.zgsg.databinding.ActivityMainBinding
import cn.xz.zgsg.dialog.AllClickDialog
import cn.xz.zgsg.dialog.LoseAppDialog
import cn.xz.zgsg.net.ControlDevice
import cn.xz.zgsg.util.*
import java.text.DateFormat
import java.text.SimpleDateFormat

/**
 * 2560 * 1600*/
class MainActivity: BaseActivity<ActivityMainBinding>(R.layout.activity_main) {

    //当前Logo点击次数
    private var logoNum = 0
    //上次点击logo时间
    private var lastLogoTime = 0L

    override fun initData() {
    }

    override fun initEvent() {
        //Logo
        mDataBind.ivLogo.setOnClickListener {
            //连点五次进入数据下载界面
            if (System.currentTimeMillis() - lastLogoTime > 2000) {
                logoNum = 0
                lastLogoTime = System.currentTimeMillis()
            } else {
                logoNum++
                if (logoNum >= 5) {
                    ARouter.to(LoadingActivity::class.java)
                }
            }
        }
        //一件全开
        mDataBind.tvOpenAll.setOnClickListener {
            AllClickDialog.newInstance(true,object : AllClickDialog.OnClickListener{
                override fun onYes() {
                    ControlDevice.openAll()
                }
                override fun onNo() {
                }
            }).show(this.supportFragmentManager,"AllClickDialog1")
        }
        //一键全关
        mDataBind.tvCloseAll.setOnClickListener {
            AllClickDialog.newInstance(false,object : AllClickDialog.OnClickListener{
                override fun onYes() {
                    ControlDevice.closeAll()
                }
                override fun onNo() {
                }
            }).show(this.supportFragmentManager,"AllClickDialog2")
        }
        //灯光管理
        mDataBind.tvLight.setOnClickListener {
            ARouter.to(LightActivity::class.java)
        }
        //设备管理
        mDataBind.tvDevice.setOnClickListener {
            ARouter.to(DeviceActivity::class.java)
        }
        //欢迎词
        mDataBind.tvWelcome.setOnClickListener {
            ARouter.to(WelcomeActivity::class.java,13182)
        }
        //通用客户端
        mDataBind.tvLocal.setOnClickListener {
            ARouter.to(LocalActivity::class.java,13182)
        }
        //二级界面
        mDataBind.tvTwo.setOnClickListener {
            ARouter.to(SecondActivity::class.java,13182)
        }
        //一楼
        mDataBind.tv1l.setOnClickListener {
            mDataBind.tv1l.background = AppHelper.getDrawable(R.mipmap.icon_btn_public_1)
            mDataBind.tv2l.background = AppHelper.getDrawable(R.mipmap.icon_btn_public)
            mDataBind.cl1l.visible()
            mDataBind.cl2l.gone()
        }
        mDataBind.tv2l.setOnClickListener {
            mDataBind.tv2l.background = AppHelper.getDrawable(R.mipmap.icon_btn_public_1)
            mDataBind.tv1l.background = AppHelper.getDrawable(R.mipmap.icon_btn_public)
            mDataBind.cl2l.visible()
            mDataBind.cl1l.gone()
        }
        //序厅",14053))
        mDataBind.tv1Xt.setOnClickListener {
            ARouter.to(Main1Activity::class.java,14053)
        }
        //条形屏",14054))
        mDataBind.tv1Txp.setOnClickListener {
            ARouter.to(Main1Activity::class.java,14054)
        }
        //大事记",14055))
        mDataBind.tv1Dsj.setOnClickListener {
            ARouter.to(Main1Activity::class.java,14055)
        }
        //创建基础",14056))
        mDataBind.tv1Kjbj.setOnClickListener {
            ARouter.to(Main1Activity::class.java,14056)
        }
        //阶段成果",14057))
        mDataBind.tv1Cgjz.setOnClickListener {
            ARouter.to(Main1Activity::class.java,14057)
        }
        //合规沙盒",14058))
        mDataBind.tv1Hgsh.setOnClickListener {
            ARouter.to(Main1Activity::class.java,14058)
        }


        //"数联网",14059))
        mDataBind.tv2Slw.setOnClickListener {
            ARouter.to(Main2Activity::class.java,14059)
        }
        //"数据发票",14060))
        mDataBind.tv2Sjfp.setOnClickListener {
            ARouter.to(Main2Activity::class.java,14060)
        }
        //"区块链",14061))
        mDataBind.tv2Qkl.setOnClickListener {
            ARouter.to(Main2Activity::class.java,14061)
        }
        //"数交所",14062))
        mDataBind.tv2Sjs.setOnClickListener {
            ARouter.to(Main2Activity::class.java,14062)
        }
        //"算力",14063))
        mDataBind.tv2Sl.setOnClickListener {
            ARouter.to(Main2Activity::class.java,14063)
        }
        //"解决方案1",14064))
        mDataBind.tv2Jj1.setOnClickListener {
            ARouter.to(Main2Activity::class.java,14064)
        }
        //"解决方案2",14065))
        mDataBind.tv2Jj2.setOnClickListener {
            ARouter.to(Main2Activity::class.java,14065)
        }
        //"解决方案3",14066))
        mDataBind.tv2Jj3.setOnClickListener {
            ARouter.to(Main2Activity::class.java,14066)
        }
        //"解决方案4",14067))
        mDataBind.tv2Jj4.setOnClickListener {
            ARouter.to(Main2Activity::class.java,14067)
        }
    }


    override fun onResume() {
        super.onResume()
        //判断应用是否过期，如果过期弹窗禁止使用
        val dateLogin = SessionUtils.getObject<DateLogin>(CommonLib.Date_Login, DateLogin::class.java)
        if (dateLogin != null){
            //正式版不处理
            if (dateLogin.states != 1){
                val format: DateFormat = SimpleDateFormat("yyyy-MM-dd")
                val fwqTime = format.parse(dateLogin.date).time
                if (fwqTime < System.currentTimeMillis()){
                    LoseAppDialog.newInstance(true,object :LoseAppDialog.OnClickListener{
                        override fun onF() {
                            finish()
                        }
                    }).show(this.supportFragmentManager,"LoseAppDialog")
                }
            }
        }else{
            LoseAppDialog.newInstance(false,object :LoseAppDialog.OnClickListener{
                override fun onF() {

                }
            }).show(this.supportFragmentManager,"LoseAppDialog2222")
        }
    }

}